package com.recycle.system.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.recycle.system.domain.Order;
import com.recycle.system.domain.WasteResource;
import com.recycle.system.domain.dto.SelectOptions;
import com.recycle.system.domain.vo.ExtendOrder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


/**
 * 订单信息Mapper接口
 *
 * @author recycle
 * @date 2023-03-11
 */

public interface OrderMapper extends BaseMapper<Order>
{
    /**
     * 查询订单信息
     *
     * @param orderId 订单信息主键
     * @return 订单信息
     */
    public Order selectOrderByOrderId(Long orderId);

    /**
     * 查询订单信息列表
     *
     * @param order 订单信息
     * @return 订单信息集合
     */
    public List<Order> selectOrderList(Order order);

    /**
     * 新增订单信息
     *
     * @param order 订单信息
     * @return 结果
     */
    public int insertOrder(Order order);

    /**
     * 修改订单信息
     *
     * @param order 订单信息
     * @return 结果
     */
    public int updateOrder(Order order);

    /**
     * 删除订单信息
     *
     * @param orderId 订单信息主键
     * @return 结果
     */
    public int deleteOrderByOrderId(Long orderId);

    /**
     * 批量删除订单信息
     *
     * @param orderIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteOrderByOrderIds(Long[] orderIds);





    /**
     * 查询商家列表
     *
     * @param
     * @return
     */
    @Select("select nick_name,user_id from sys_user where user_type ='02'")
    List<SelectOptions> selectMerchant();


    /**
     * 完成支付后更新订单状态
     * @param
     * @return
     */
    @Update("update sys_order set `status` = #{status} where order_id = #{orderId}")
   int updateOrderStatus(@Param("orderId") Long orderId, @Param("status") Long status);

    /**
     * 居民查询历史申请
     * @param
     * @return
     */
    @Select("select a.order_id,a.description,a.create_time,a.update_time ,b.pre_income,b.actual_income,b.percentage " +
            "from sys_order a left join order_detail b on a.order_id = b.order_id where a.publisher_id = #{orderId}")
    List<ExtendOrder> selectResidentExtendOrder(@Param("orderId") Long orderId);



    /**
     * 商家查询历史申请
     * @param
     * @return
     */
    @Select("select a.order_id,a.description,a.create_time,a.update_time ,b.pre_income,b.actual_income,b.percentage " +
            "from sys_order a left join order_detail b on a.order_id = b.order_id where a.finisher_id = #{orderId}")
    List<ExtendOrder> selectMerchantExtendOrder(@Param("orderId") Long orderId);
}
